package cn.jbit.test.io;

import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.util.Scanner;

/**
 * 源码学院只为培养优秀的bat程序员而生
 *
 * @author 学员张在成
 * @data 2021/6/27
 */
public class BioTestClient {

    public static void main(String[] args) throws IOException {

        Socket  socket=new Socket("localhost",8083);
        //开始接收服务端回送回来的数据
        InputStream inputStream = socket.getInputStream();

        while (true) {

            Scanner scanner=new Scanner(System.in);
            String next = scanner.next();
            OutputStream outputStream = socket.getOutputStream();
            System.out.println("client send data give server");
            outputStream.write(next.getBytes());


            byte[] bytes = new byte[1024];
            int read = inputStream.read(bytes);
            int length = 0;
            System.out.println(read);

            //while ((length = read) > 0) {
                //======================下面是读取数据================
                System.out.println("读取字节长度：" + length);
                System.out.println("client recevive server send data is：" + new String(bytes));
            //}
            outputStream.flush();

            //socket.close();
        }
    }
}
